from DBA.dbmanager import DBInterface

class ListWifi:
	def __init__(self):
		self.id			= {"key":"ID","value":""}
		self.ensCelluleWifi	= []
		self.__interfacebase	= DBInterface()
		self.id["value"]	= str(self.__interfacebase.createNewID());
	
	def createByListeDico(self,liste):
	    for cellule in liste:
		ce = CelluleWifi()
		ce.createByDico(cellule)
		self.addCellule(ce)

	def addCellule(self,Cellule):
		self.ensCelluleWifi.append(Cellule)
	
	def nbCellules(self):
		return self.ensCelluleWifi.count()
	
	def insertToDb(self,idMesure):
		inter   = self.createConfigListDico(idMesure)
		self.__interfacebase.insert(self.__interfacebase.iwlisttablename,self.__interfacebase.iwlistmapping,inter)
		for cellule in self.ensCelluleWifi:
			cellule.insertToDb(self.id["value"])

	def updateIntoDb(self,idMesure):
		inter   = self.createConfigListDico(idMesure)
		self.__interfacebase.update(self.__interfacebase.iwlisttablename,self.__interfacebase.iwlistmapping,inter)
		for cellule in self.ensCelluleWifi:
			cellule.updateIntoDb(self.id["value"])
	
	def createConfigListDico(self,idMesure):
		dico ={}
		dico[self.id["key"]]		= self.id["value"]
		dico["link_me"]			= idMesure
		return dico

class CelluleWifi:
	def __init__(self):
		self.id			= {"key":"ID","value":""}
		self.extra		= {"key":"Extra","value":""}
		self.bitRate		= {"key":"Bit Rates","value":""}
		self.encrytionKey	= {"key":"Encryption key","value":""}
		self.mode		= {"key":"Mode","value":""}
		self.address		= {"key":"Address","value":""}
		self.quality		= {"key":"Quality","value":""}
		self.channel		= {"key":"Channel","value":""}
		self.essid		= {"key":"ESSID","value":""}
		self.__interfacebase	= DBInterface()
	
	def createByDico(self,dico):
		self.essid["value"]		= dico[self.essid["key"]]
		self.mode["value"]		= dico[self.mode["key"]] 
		self.extra["value"]		= dico[self.extra["key"]]
		self.encrytionKey["value"]	= dico[self.encrytionKey["key"]]
		self.address["value"]		= dico[self.address["key"]]
		self.bitRate["value"]		= dico[self.bitRate["key"]]
		self.quality["value"]		= dico[self.quality["key"]]
		self.channel["value"]		= dico[self.channel["key"]]
		 
		
		

	def insertToDb(self,idList):
		dico 	= self.createConfigListDico(idList)
		self.__interfacebase.insert(self.__interfacebase.celluleIwlisttablename,self.__interfacebase.celluleIwlistmapping,dico)
	
	def updateIntoDb(self,idList):
		dico 	= self.createConfigListDico(idList)
		self.__interfacebase.update(self.__interfacebase.celluleIwlisttablename,self.__interfacebase.celluleIwlistmapping,dico)
		
	
	def createConfigListDico(self,idList):
		dico ={}
		dico[self.id["key"]]		= idList
		dico[self.essid["key"]]		= self.essid["value"]
		dico[self.mode["key"]]		= self.mode["value"]
		dico[self.extra["key"]]		= self.extra["value"]
		dico[self.encrytionKey["key"]]	= self.encrytionKey["value"]
		dico[self.address["key"]]	= self.address["value"]
		dico[self.bitRate["key"]]	= self.bitRate["value"]
		dico[self.quality["key"]]	= self.quality["value"]
		dico[self.channel["key"]]	= self.channel["value"]
		return dico
